package csu.edu.flatprogram.controller.front;

import com.baomidou.mybatisplus.extension.api.R;
import csu.edu.flatprogram.common.CommonResponse;
import csu.edu.flatprogram.entity.DonateGoods;
import csu.edu.flatprogram.entity.RaiseFund;
import csu.edu.flatprogram.service.RaiseFundService;
import csu.edu.flatprogram.vo.DonateGoodsVO;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.plugin.com.event.COMEventHandler;

import java.util.List;

@RestController
@RequestMapping("/flat/raisefunds")
public class RaiseFundController {

    @Autowired
    private RaiseFundService raiseFundService;


    //查询所有募捐信息
    @GetMapping("/select")
    public CommonResponse<List<RaiseFund>> getAllRaiseFundInformations(){
        return raiseFundService.getAllRaiseFundInformations();
    }

    //查询某个ID名称的募捐信息
    @GetMapping("/select/{fundid}")
    public CommonResponse<RaiseFund> getRaiseFundById(@PathVariable("fundid") String fundid){
        return raiseFundService.getRaiseFundById(fundid);
    }

//    //新增一条募捐信息
//    @GetMapping("/{fundid}/{fundname}/{details}/add")
//    public CommonResponse<RaiseFund> addRaiseFund(@PathVariable("fundid") String fundid,
//                                                  @PathVariable("fundname") String fundname,
//                                                  @PathVariable("details") String funddetails){
//        return raiseFundService.addRaiseFund(fundid,fundname,funddetails);
//    }
//
//    //更新一条募捐信息
//    @GetMapping("/{fundid}/{fundname}/{details}/update")
//    public CommonResponse<RaiseFund> updateRaiseFund(@PathVariable("fundid") String fundid,
//                                                  @PathVariable("fundname") String fundname,
//                                                  @PathVariable("details") String funddetails){
//        return raiseFundService.updateRaiseFund(fundid,fundname,funddetails);
//    }

    //新增募捐信息
    @PostMapping("/add")
    public CommonResponse<RaiseFund> insertRaisefund(@RequestBody RaiseFund raiseFund){
        return raiseFundService.insertRaisefund(raiseFund);
    }

    //更新募捐信息
    @PostMapping("/update")
    public CommonResponse<RaiseFund> updateRaisefund(@RequestBody RaiseFund raiseFund){
        return raiseFundService.updateRaisefund(raiseFund);
    }

    //根据ID删除某条募捐信息
    @DeleteMapping("/delete/{fundid}")
    public CommonResponse<RaiseFund> deleteRaiseFund(@PathVariable("fundid") String fundid){
        return raiseFundService.deleteRaiseFund(fundid);
    }

    //查询某个ID名称下所有捐赠的物品信息
    @GetMapping("/{fundid}/donategoods/select")
    public CommonResponse<List<DonateGoods>> getDonateGoodsByRaiseFundId(@PathVariable("fundid") String fundid){
        return raiseFundService.getDonateGoodsByRaiseFundId(fundid);
    }

    //查询某个ID名称下所有捐赠的物品信息（包括用户信息）
    @GetMapping("/{fundid}/donategoodsvo/select")
    public CommonResponse<List<DonateGoodsVO>> getDonateGoodsVOByRaiseFundId(@PathVariable("fundid") String fundid){
        return raiseFundService.getDonateGoodsVOByRaiseFundId(fundid);
    }

    //查询所有募捐物品信息(包括用户信息)
    @GetMapping("/donategoods/select")
    public CommonResponse<List<DonateGoodsVO>> getDonateGoods(){
        return raiseFundService.getDonateGoods();
    }

    //根据ID查询单个捐赠物品信息（包括用户信息）
    @GetMapping("/donategoods/{goodsid}/select")
    public CommonResponse<DonateGoodsVO> getDonateGoodById(@PathVariable("goodsid") int goodsid){
       return raiseFundService.getDonateGoodById(goodsid);
    }

//    //新增一条捐赠物品信息
//    @GetMapping("/donategoods/{userid}/{fundid}/{platform}/{category}/{number}/{description}/add")
//    public CommonResponse<DonateGoods> addDonateGood(@PathVariable("userid") String userid,
//                                                     @PathVariable("fundid") String fundid,
//                                                     @PathVariable("platform") String goodsplatform,
//                                                     @PathVariable("category") String goodscategory,
//                                                     @PathVariable("number") String goodsnumber,
//                                                     @PathVariable("description") String goodsdescription){
//        return raiseFundService.addDonateGood(userid,fundid,goodsplatform,goodscategory,goodsnumber,goodsdescription);
//    }
//
//    //根据ID更新一条捐赠物品信息
//    @GetMapping("/donategoods/{goodsid}/{userid}/{fundid}/{platform}/{category}/{number}/{description}/update")
//    public CommonResponse<DonateGoods> updateDonateGood(@PathVariable("goodsid") int goodsid,
//                                                        @PathVariable("userid") String userid,
//                                                        @PathVariable("fundid") String fundid,
//                                                        @PathVariable("platform") String goodsplatform,
//                                                        @PathVariable("category") String goodscategory,
//                                                        @PathVariable("number") String goodsnumber,
//                                                        @PathVariable("description") String goodsdescription){
//       return raiseFundService.updateDonateGood(goodsid,userid,fundid,goodsplatform,goodscategory,goodsnumber,goodsdescription);
//    }

    //新增一条捐赠物品信息
    @PostMapping("/donategoods/add")
    public CommonResponse<DonateGoods> insertDonategoods(@RequestBody DonateGoods donateGoods){
        return raiseFundService.insertDonategoods(donateGoods);
    }
//
    //更新一条捐赠物品信息
    @PostMapping("/donategoods/update")
    public CommonResponse<DonateGoods> updateDonategoods(@RequestBody DonateGoods donateGoods){
        return raiseFundService.updateDonategoods(donateGoods);
    }


    //根据ID删除募捐物品信息
    @DeleteMapping("/donategoods/delete/{goodsid}")
    public CommonResponse<DonateGoods> deleteDonateGoodById(@PathVariable("goodsid") int goodsdid){
        return raiseFundService.deleteDonateGoodById(goodsdid);
    }

}
